package com.achilles.fragment;


import android.support.v4.app.Fragment;
import android.view.View;

import com.achilles.database.DBManager;
import com.achilles.playtask.R;
import com.achilles.widget.ScoreView;

/**
 * A simple {@link Fragment} subclass.
 */
public class ScoreFragment extends BaseFragment {

    private ScoreView mScoreView;
    public ScoreFragment() {
        // Required empty public constructor
    }

    @Override
    protected int getLayoutID() {
        return R.layout.fragment_score;
    }

    @Override
    protected void onViewCreated(View view) {
        mScoreView = (ScoreView) view.findViewById(R.id.scoreView);
        showScoreWithAnimation();
    }

    public void showScoreWithAnimation() {
        if (mScoreView == null) {
            return;
        }
        mScoreView.setScore(DBManager.getInstance().getScore());
        mScoreView.showScore();
    }

    public static ScoreFragment getInstance() {
        return new ScoreFragment();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            showScoreWithAnimation();
        }
    }
}
